package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 使用Constructor完成对Student的实例化
 * 有参构造器和无参构造器分别实例化
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class cls = Class.forName("reflect.Student");
        Constructor c = cls.getConstructor(String.class,int.class,char.class);//Student(String,int,char)
        Object obj = c.newInstance("李四",36,'女');
        System.out.println(obj);

        Constructor c2 = cls.getConstructor();
        Object obj2 = c2.newInstance();
        System.out.println(obj2);
    }
}
